<%@page import="service.CategoryService"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page import="service.ArticleService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include  file="../common/taglib.jsp"%>
<%
	CategoryService categoryService = new CategoryService();
	List list = categoryService.list();
	pageContext.setAttribute("list", list);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>文章新增</title>
<link rel="stylesheet" type="text/css" href="${basePath}/static/css/public.css"/>
<link rel="stylesheet" type="text/css" href="${basePath}/static/css/index.css"/>

<script src="${basePath}/static/js/jQuery.js"></script>
<script src="${basePath}/static/layui/layui.all.js" charset="utf-8"></script>
<link rel="stylesheet" href="${basePath}/static/layui/css/layui.css" media="all">
</head>
<body>
	<h1>文章新增</h1>
	<div class="h60">
		<a href="article.jsp" class='fr'>
			<button type="button" class="layui-btn layui-btn-warm">返回</button>
		</a>
	</div>
	
	
	<form action='addArticleController.jsp' method="post" onsubmit="return validate()" class="layui-form" lay-filter="form0">
		<div class="layui-form-item">
            <label class="layui-form-label">文章标题</label>
			<div class="layui-input-block">
	          <input type="text" name="header" autocomplete="off" placeholder="请输入文章标题" class="layui-input">
	        </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">文章名称</label>
			<div class="layui-input-block">
	          <input type="text" name="name" autocomplete="off" placeholder="请输入文章名称" class="layui-input">
	        </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">文章概要</label>
			<div class="layui-input-block">
	          <input type="text" name="description" autocomplete="off" placeholder="请输入文章概要" class="layui-input">
	        </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文章专题</label>
			<div class="layui-input-block">
	         
	         <select name="categoryId">
		        <option value="">请选择</option>
		        <c:forEach items="${list}" var="item" varStatus="status">
		        	<option value="${item.category_id }">${item.category_name }</option>
		        </c:forEach>
		      </select>
	         
	        </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">文章内容</label>
			<div class="layui-input-block">
	          <textarea  name="content" autocomplete="off" placeholder="请输入文章内容" class="layui-textarea"></textarea>
	        </div>
        </div>
        
        <div class="layui-input-block">
          <button type="submit" class="layui-btn">立即提交</button>
        </div>
	</form>
	
	<script>
		function validate(){
			if(!$('input[name="header"]').val()){
				layer.msg("文章标题不允许为空！");
				return false;
			}
			if(!$('input[name="name"]').val()){
				layer.msg("文章名称不允许为空！");
				return false;
			}
			if(!$('input[name="description"]').val()){
				layer.msg("文章概要不允许为空！");
				return false;
			}
			if(!$('select[name="categoryId"]').val()){
				layer.msg("文章专题不允许为空！");
				return false;
			}
			if(!$('textarea[name="content"]').val()){
				layer.msg("文章内容不允许为空！");
				return false;
			}
			return true;
		}
		
		layui.use("form", function () {
			 var form = layui.form;
			 form.render(null,'form0'); //动态加载form0容器内的所有组件
		}) 
		
	</script>
</body>
</html>
